//
//  CGCollectionCompanyCell.m
//  SchoolClient
//
//  Created by mac on 15/11/13.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "CGCollectionCompanyCell.h"

@implementation CGCollectionCompanyCell

@synthesize titleLabel,companyLabel,sizeLabel,addressLabel,startTimeLable,middleLable,endTimeLable,circleImage;

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        //招聘标题
        titleLabel = [[UILabel alloc]init];
        titleLabel.numberOfLines = 0;
        titleLabel.font = [UIFont systemFontOfSize:16];
        //titleLabel.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:titleLabel];
        
        //招聘单位
        companyLabel = [[UILabel alloc]init];
        companyLabel.numberOfLines = 0;
        companyLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:companyLabel];
        
        //地点：
        sizeLabel = [[UILabel alloc]init];
        sizeLabel.font = [UIFont systemFontOfSize:13];
        sizeLabel.textColor = [UIColor darkGrayColor];
        [self.contentView addSubview:sizeLabel];
        
        //上斑区域
        addressLabel = [[UILabel alloc]init];
        addressLabel.numberOfLines = 0;
        addressLabel.font = [UIFont systemFontOfSize:13];
        addressLabel.textColor = [UIColor darkGrayColor];
        //addressLabel.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:addressLabel];
        
        //招聘开始时间
        startTimeLable = [[UILabel alloc]init];
        startTimeLable.font = [UIFont systemFontOfSize:13];
        startTimeLable.textColor = [UIColor darkGrayColor];
        startTimeLable.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:startTimeLable];
        
        //中间联接符
        middleLable = [[UILabel alloc]init];
        middleLable.font = [UIFont systemFontOfSize:13];
        middleLable.textColor = [UIColor darkGrayColor];
        middleLable.textAlignment = NSTextAlignmentLeft;
        //middleLable.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:middleLable];
        
        //招聘结束时间
        endTimeLable = [[UILabel alloc]init];
        //endTimeLable.text = @"2015-11-14 11:37";
        endTimeLable.font = [UIFont systemFontOfSize:13];
        endTimeLable.textColor = [UIColor darkGrayColor];
        endTimeLable.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:endTimeLable];
        
        //在前面添加一圆圈
        circleImage = [[UIImageView alloc]init];
        circleImage.image = [UIImage imageNamed:@"mine_not_check_icon"];
        [self.contentView addSubview:circleImage];
        circleImage.hidden = YES;
        
        
    }
    return self;
}


-(void)setProductFrame:(CGCollectionCompanyFrame *)productFrame{
    
    _productFrame = productFrame;
    
    titleLabel.text = productFrame.product.title;
    companyLabel.text = productFrame.product.name;
    sizeLabel.text = @"地点:";
    addressLabel.text = productFrame.product.workingPlace;
    startTimeLable.text = [self getTimeWithDate:productFrame.product.recruitmentTimeStart];
    endTimeLable.text = [self getTimeWithDate:productFrame.product.recruitmentTimeEnd];
    if (endTimeLable.text.length == 0){
        middleLable.text = @"";
    }else{
        middleLable.text = @"至";
    }
    self.cell_id = productFrame.product.info_id;
    
    titleLabel.frame = productFrame.titleLabelF;
    companyLabel.frame = productFrame.companyLabelF;
    sizeLabel.frame = productFrame.sizeLabelF;
    addressLabel.frame = productFrame.addressLabelF;
    startTimeLable.frame = productFrame.timeStartLabelF;
    middleLable.frame = productFrame.linkLabelF;
    endTimeLable.frame = productFrame.timeEndLabelF;
    circleImage.frame = productFrame.circleImageF;
    
    
}




-(NSString *)getTimeWithDate:(NSString *)timeStr{
    
    NSDateFormatter *inputFormatter = [[NSDateFormatter alloc]init];
    NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];
    [inputFormatter setLocale:locale];
    [inputFormatter setDateFormat:@"MMM dd, yyyy hh:mm:ss aa"];
    NSDate *inputDate = [inputFormatter dateFromString:timeStr];
    //创建日期模板对象,设置模板的显示格式
    NSDateFormatter *outputFormatter = [[NSDateFormatter alloc]init];
    //outputFormatter.dateFormat = @"yyyy-MM-dd HH:mm";
    outputFormatter.dateFormat = @"yyyy-MM-dd";
    NSString *outputDate = [outputFormatter stringFromDate:inputDate];     //自动转换成当地时间
    return outputDate;
}


@end
